﻿
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SZHL.UI.AppCode;
using System.Data;
using SZHL.Data;


namespace SZHL.UI.View
{
    public partial class CommonAdd : BasePage
    {
        public FormUControl WFForm
        {

            get { return UserControl.Controls[0] as FormUControl; }
        }
        public JH_Auth_FormBase FormBaseData
        {
            get
            {
                return ViewState[hidFormCode.Value] == null ? new FormHelp().GetFormCodeByFormCode(hidFormCode.Value) : (JH_Auth_FormBase)ViewState[hidFormCode.Value];
            }
            set
            {
                ViewState[hidFormCode.Value] = value;
            }
        }

        protected override void OnInit(EventArgs e)
        {

            hidFormCode.Value = Request.QueryString["FormCode"] ?? "";
            //加载用户控件
            FormUControl Control = LoadControl("/View/UCForm/" + FormBaseData.FormAddUrl) as FormUControl;
            UserControl.Controls.Add(Control);
            base.OnInit(e);
            //为用户控件加载用户数据
            Control.UserInfo = UserInfo;
            if (!IsPostBack)
            {

                Control.initALLForm(hidFormCode.Value);

                //初始化添加表单
                Control.initAddForm(hidFormCode.Value);
            }
            btSendForm.Attributes.Add("onclick", "this.value='正在提交中,請稍等……';this.disabled=true;" + this.GetPostBackEventReference(btSendForm) + ";");

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btSendForm_Click(object sender, EventArgs e)
        {
            SaveForm();

        }
        /// <summary>
        /// 保存单据,如果是暂存，则冻结单据
        /// </summary>
        /// <param name="strIsSuspend"></param>
        public void SaveForm()
        {

            string strVerifyMsg = WFForm.VerifyAddForm();
            if (strVerifyMsg == "")
            {
                FormHelp FormHelp = new FormHelp();
                int intFormID = FormHelp.addForm(FormBaseData.FormTable, UserInfo.User.UserName);
                hidFormID.Value = intFormID.ToString();
                //为表单添加数据
                //执行表单保存数据方法
                try
                {
                    WFForm.SaveForm(intFormID, "ADD");
                    //发送通知
                    AlertMSG("0", "操作成功");
                }
                catch (Exception)
                {
                    FormHelp.DelForm(intFormID, FormBaseData.FormTable);
                    AlertMSG("1", "操作失败");

                }

            }
            else
            {
                AlertMSG("1", strVerifyMsg);
            }
        }


    }
}